package com.cincc.cinccimdemo.viewholder;

import android.content.Context;
import android.content.Intent;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cincc.cinccimdemo.R;
import com.cincc.cinccimdemo.adapter.ConversationAdapter;
import com.cincc.cinccimdemo.common.AttrConstants;
import com.cincc.cinccimdemo.common.EmojiUtils;
import com.cincc.cinccimdemo.model.MessageInfoUI;
import com.cincc.cinccimdemo.ui.conversation.sequence.SequenceActivity;
import com.cincc.im.model.enums.ImSendType;
import com.cincc.im.model.message.ImSequenceMessage;
import com.cincc.im.model.message.ImTextMessage;

public class ReceiveSequenceViewHolder extends MessageContentHolder {
    public ImageView iv_face;
    public TextView tv_message;
    public TextView tv_username;
    public TextView tv_time;
    public TextView join_text;

    public ReceiveSequenceViewHolder(Context context, View itemView, ConversationAdapter adapter) {
        super(context, itemView, adapter);
        iv_face = itemView.findViewById(R.id.iv_face);
        tv_message = itemView.findViewById(R.id.tv_message);
        tv_username = itemView.findViewById(R.id.username_text);
        tv_time = itemView.findViewById(R.id.tv_time);
        join_text = itemView.findViewById(R.id.joinTextView);
    }

    @Override
    public void bindView(MessageInfoUI uiMessage, int position) {
        super.bindView(uiMessage, position);
        ImSequenceMessage imSequenceMessage = (ImSequenceMessage) uiMessage.getMessageInfo().imMessage;

        StringBuilder showContent = new StringBuilder();
        showContent.append(imSequenceMessage.msgContent).append("\n");

        for (int i = 0; i < imSequenceMessage.participantList.size(); i++) {
            showContent.append(i + 1).append(" ").append(imSequenceMessage.participantList.get(i).nickName).append("\n");
        }

        tv_message.setText(showContent);
        tv_username.setText(uiMessage.getMessageInfo().senderName);
        tv_username.setVisibility(ImSendType.isP2P(uiMessage.getMessageInfo().imSendType) ? View.GONE : View.VISIBLE);
        join_text.setOnClickListener(v -> {
            Intent i = new Intent(context, SequenceActivity.class);
            i.putExtra(AttrConstants.IS_CREATE_SEQUENCE, false);
            i.putExtra(AttrConstants.SEQUENCE_ID, imSequenceMessage.sequenceId);
            i.putExtra(AttrConstants.GROUP_ID, imSequenceMessage.fromGroupId);
            context.startActivity(i);
        });
    }
}
